<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" th:href="@{/favicon.ico}" >
    <link rel="shortcut icon" th:href="@{/favicon.ico}"/>
    <link rel="bookmark" th:href="@{/favicon.ico}"/>
    <link rel="Shortcut Icon" th:href="@{/favicon.ico}" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/lib/html5.js"></script>
    <script type="text/javascript" src="/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css" />

    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" type="text/css" href="/lib/zTree/zTreeStyle.css">
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script><![endif]-->
    <!--/meta 作为公共模版分离出去-->
    <title>资源配置</title>

</head>
<body>
<!--_header 作为公共模版分离出去-->
<div th:replace="common/header::header"></div>
<!--_menu 作为公共模版分离出去-->
<div th:replace="common/menu::menu"></div>

<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont"></i> <a href="/" class="maincolor">首页</a>
        <span class="c-999 en">&gt;</span><span class="c-666">资源配置</span>
    </nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="panel panel-default">
                <div class="panel-header">资源配置</div>
                <div class="panel-body text-c form-horizontal">

                    <div >
                        <ul id="treeDemo" class="ztree"></ul>
                    </div>
                </div>
                <span style="color:red;">* &nbsp;目前仅支持修改菜单名，禁用/启用菜单。</span>
            </div>

        </article>
    </div>
</section>



<script src="/lib/zTree/jquery.ztree.all-3.5.min.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
$(function () {
    var setting={
        async: { // 属性配置
            enable: true,
            url:"/admin/getNodes",
            type: 'get'
        },
        edit: {
            drag: {
                isCopy: false,
                isMove: true
            },
            enable: true,
            showRemoveBtn: showRemoveBtn,
            showRenameBtn: showRenameBtn,
            removeTitle:"禁用/启用",
            renameTitle:"重命名"
        },
        view: { showLine: false },//不是最后一个node，其他node不显示name,需要设置？
        callback: {
            onAsyncSuccess:onAsyncSuccess,
            beforeRename: beforeRename,
            beforeRemove: beforeRemove
        }
    };
    var zTreeObj = $.fn.zTree.init($("#treeDemo"), setting);

    //异步加载成功回调函数
    function onAsyncSuccess(event, treeId, treeNode, msg) {
        zTreeObj.expandAll(true);//展开所有结点
    }

    //是否进行删除节点
    function beforeRemove(treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.selectNode(treeNode);
        if (treeNode.isActive=="1"){
            layer.confirm("确认停用 菜单 --" + treeNode.name + "-- 吗？", function(index){
                $.ajax({
                    url:"/admin/updateResourceToActive",
                    type:"post",
                    data:{
                        "id":treeNode.id,
                        "activeFlag":"0"
                    },
                    dataType:"json",
                    success:function(data,state) {
                        if (data){
                            layer.msg("修改成功");
                        } else{
                            layer.msg("修改失败");
                        }
                    },
                    error:function () {
                        alert("系统异常，删除失败。");
                    }
                });
                layer.close(index);
                setTimeout('window.location.href="/admin/tree"', 1000);
            },function () {
                window.location.href="/admin/tree";
            });
        }else{
            layer.confirm("确认启用 菜单 -- " + treeNode.name + "-- 吗？", function(index){
                $.ajax({
                    url:"/admin/updateResourceToActive",
                    type:"post",
                    data:{
                        "id":treeNode.id,
                        "activeFlag":"1"
                    },
                    dataType:"json",
                    success:function(data,state) {
                        if (data){
                            layer.msg("修改成功");
                        } else{
                            layer.msg("修改失败");
                        }
                    },
                    error:function () {
                        alert("系统异常，删除失败。");
                    }
                });
                layer.close(index);
                setTimeout('window.location.href="/admin/tree"', 1000);
            },function () {
                window.location.href="/admin/tree";
            });
        }
    }
    //判断修改后的节点是否为空，为空取消，否则提交
    function beforeRename(treeId, treeNode, newName, isCancel) {
        if (newName.length == 0) {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            zTree.cancelEditName();
            alert("节点名称不能为空.");
            return false;
        }else{
            $.ajax({
                url:"/admin/updateNode",
                type:"post",
                data:{
                    "id":treeNode.id,
                    "name":newName
                },
                dataType:"json",
                success:function(data) {
                    console.log("updateName  data=",data);
                    if (data){
                        layer.msg("修改成功");
                    } else{
                        layer.msg("修改失败");
                    }
                },
                error: function () {
                    alert("系统异常，修改失败");
                }
            });
        }
    }
    function showRemoveBtn(treeId, treeNode) {
        return treeNode;
    }
    function showRenameBtn(treeId, treeNode) {
        return treeNode;
    }
})


</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
